package com.lyloou.practicerabbitmq.controller;

import com.lyloou.practicerabbitmq.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author lilou
 * @since 2021/2/18
 */
@Controller
@Slf4j
public class PayController {
    @Autowired
    OrderService orderService;

    @RequestMapping("/pay/{orderId}")
    public String pay(@PathVariable String orderId, Model model) {
        try {
            orderService.pay(orderId);
            model.addAttribute("orderId", orderId);
            return "success";
        } catch (Exception e) {
            log.error("支付失败：" + orderId, e);
            model.addAttribute("errorMsg", e.getMessage());
            return "failorder";
        }
    }
}
